import request from "@/utils/request";
import axios from "axios";
import { getToken } from "xqjr-module-auth/utils";

export function selectDefaultGroupIdReq() {
  return request({
    url: `/hr/api/v1/saleUsers/selectDefaultGroupId`,
    method: "get"
  });
}
export function selectCompanyBySaleUserIdReq(userId) {
  return request({
    url: `/hr/api/v1/companySaleUsers/selectCompanyBySaleUserId/${userId}`,
    method: "get"
  });
}

// 统计
export function rebateOverviewListReq(params) {
  return request({
    url: `/hr/api/v1/saleRebatesRecords/rebateOverviewList`,
    method: "get",
    params
  });
}
export function rebateOverviewGroupReq(params) {
  return request({
    url: `/hr/api/v1/saleRebatesRecords/rebateOverviewGroup`,
    method: "get",
    params
  });
}
export function rebateOverviewMonthReq(params) {
  return request({
    url: `/hr/api/v1/saleRebatesRecords/rebateOverviewMonth`,
    method: "get",
    params
  });
}

// 提成计算
export function saleRebatesRecordsReq(params) {
  return request({
    url: `/hr/api/v1/saleRebatesRecords`,
    method: "get",
    params
  });
}
export function tileCompanyByUserReq() {
  return request({
    url: `/hr/api/v1/companies/tileCompanyByUser`,
    method: "get"
  });
}
export function calculationRebatesReq(data) {
  return request({
    url: `/hr/api/v1/saleRebatesRecords/calculationRebates`,
    method: "post",
    data
  });
}

// 服务费
export function saleServerCostRecordsReq(params) {
  return request({
    url: `/hr/api/v1/saleServerCostRecords`,
    method: "get",
    params
  });
}
export function overlaidDataReq(data) {
  return request({
    url: `/hr/api/v1/saleServerCostRecords/overlaidData`,
    method: "put",
    data
  });
}

// 提成规则
export function selectSiteRebatesRulesReq(rulesName) {
  const p = rulesName ? `?rulesName=${rulesName}` : "";
  return request({
    url: `/hr/api/v1/saleRebatesRules/selectSiteRebatesRules${p}`,
    method: "get"
  });
}
export function addSaleRebatesRulesReq(data) {
  return request({
    url: `/hr/api/v1/saleRebatesRules`,
    method: "post",
    data
  });
}
export function updateSaleRebatesRulesReq(data) {
  return request({
    url: `/hr/api/v1/saleRebatesRules`,
    method: "put",
    data
  });
}
export function delSaleRebatesRulesReq(saleRebatesRulesId) {
  return request({
    url: `/hr/api/v1/saleRebatesRules/${saleRebatesRulesId}`,
    method: "delete"
  });
}
export function selectBindCompanyReq(params) {
  return request({
    url: `/hr/api/v1/saleRebatesRules/selectBindCompany`,
    method: "get",
    params
  });
}

// 销售
export function saleUsersReq(data) {
  return request({
    url: `/hr/api/v1/saleUsers`,
    method: "post",
    data
  });
}
export function updateSaleUsersReq(data) {
  return request({
    url: `/hr/api/v1/saleUsers`,
    method: "put",
    data
  });
}
export function exportSaleUsersReq(params) {
  return axios({
    url: `/hr/api/v1/saleUsers/exportSale`,
    method: "get",
    params,
    responseType: "blob",
    headers: {
      token: getToken(),
      "Content-Type": "application/json"
    }
  });
}
export function delSaleUsersReq(saleUserId) {
  return request({
    url: `/hr/api/v1/saleUsers/${saleUserId}`,
    method: "delete"
  });
}
export function selectSaleByGroupIdReq(params) {
  return request({
    url: `/hr/api/v1/saleUsers/selectSaleByGroupId`,
    method: "get",
    params
  });
}

// 分组
export function selectGroupTreeReq(groupOrAdminName) {
  const p = groupOrAdminName ? `?groupOrAdminName=${groupOrAdminName}` : "";
  return request({
    url: `/hr/api/v1/saleUsers/selectGroupTree${p}`,
    method: "get"
  });
}
export function saveGroupReq(data) {
  return request({
    url: `/hr/api/v1/saleUsers/saveGroup`,
    method: "post",
    data
  });
}
export function updateGroupReq(data) {
  return request({
    url: `/hr/api/v1/saleUsers/updateGroup`,
    method: "put",
    data
  });
}
// 销售分组管理员
export function queryUserListLessToMeAddReq() {
  return request({
    url: `/hr/api/v1/users/queryUserListLessToMeAdd`,
    method: "get"
  });
}

// 销售
export function queryUserListLessToMeReq() {
  return request({
    url: `/hr/api/v1/users/queryUserListLessToMe`,
    method: "get"
  });
}
export function selectGroupInfoReq(groupId) {
  return request({
    url: `/hr/api/v1/saleUsers/selectGroupInfo/${groupId}`,
    method: "get"
  });
}
export function deleteGroupReq(groupId) {
  return request({
    url: `/hr/api/v1/saleUsers/deleteGroup/${groupId}`,
    method: "delete"
  });
}
